<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class Index extends MY_Controller {

	function __construct() {
		parent::__construct();
		$this -> sidebar = "Index";
		
	}

	function Index() {
        redirect('/admin', 'refresh');
	}


	//修改
	function importExcel() {
		$this -> load -> model("Patent_model");
		$this -> load -> model("Author_model");
        $this -> load -> model("User_model");
		$sql = " select id,author from db_patent where id > 3790";
		$list =$this->Patent_model->query($sql);
		foreach ($list as $k=>$v){
			$data_id = $v['id'];
			$usernamel =explode(",",$v['author']) ;
			$dept_name = '';
			foreach ($usernamel as $k1=>$v1){
				$sql2 = " SELECT id,usercode,username,dept_name,`type` from db_user where is_del = 0 and username ='".$v1."'";
				$ulist =$this->User_model->query($sql2);
				if($ulist){
					$dept_name = $ulist[0]['dept_name'];
				    $addsql = " INSERT INTO db_author ( `type`, `data_id`, `identity`, `author_id`, `author_name`, `created`) VALUES ( 3, ".$data_id.", ".$ulist[0]['type'].", ".$ulist[0]['id'].", '".$ulist[0]['username']."', 1701929340);";
					$aut =$this->Author_model->execute($addsql);
					continue;
				}
			}
			switch($dept_name){
				case "机械工程分院": $dept_name = '机电分院';
					break;
				case "电气电子工程分院": $dept_name = '机电分院';
					break;
				case "机械工程学院": $dept_name = '机电分院';
					break;
				case "鉴湖学院": $dept_name = '鉴湖分院';
					break;
				case "绍兴职业教育中心": $dept_name = '职能管理部门';
					break;	
			}

			$updatesql = "UPDATE db_patent SET dept_name = '".$dept_name."' where id = ".$v['id'];
			$updateP =$this->Patent_model->execute($updatesql);
			// var_dump($v['id']);
			// var_dump($dept_name);
		}

		// var_dump($list);
        // redirect('/admin', 'refresh');
	}

	//考核表
	function importExcel1() {
		$this -> load -> model("Patent_kh_model");
		$this -> load -> model("Author_model");
        $this -> load -> model("User_model");
		$sql = " select id,author from db_patent_kh where id > 4143";
		$list =$this->Patent_kh_model->query($sql);
		foreach ($list as $k=>$v){
			$data_id = $v['id'];
			$usernamel =explode(",",$v['author']) ;
			$dept_name = '';
			$authorcode = '';
			foreach ($usernamel as $k1=>$v1){
				$sql2 = " SELECT id,usercode,username,dept_name,`type` from db_user where is_del = 0 and username ='".$v1."'";
				$ulist =$this->User_model->query($sql2);

				if($ulist){
					$dept_name = $ulist[0]['dept_name'];
					$authorcode .= ','.$ulist[0]['usercode'];
				    // $addsql = " INSERT INTO db_author ( `type`, `data_id`, `identity`, `author_id`, `author_name`, `created`) VALUES ( 3, ".$data_id.", ".$ulist[0]['type'].", ".$ulist[0]['id'].", '".$ulist[0]['username']."', 1701929340);";
					// $aut =$this->Author_model->execute($addsql);
					continue;
				}else{
					$authorcode .= ','.'**';
				}
			}
			switch($dept_name){
				case "机械工程分院": $dept_name = '机电分院';
					break;
				case "电气电子工程分院": $dept_name = '机电分院';
					break;
				case "机械工程学院": $dept_name = '机电分院';
					break;
				case "鉴湖学院": $dept_name = '鉴湖分院';
					break;
				case "绍兴职业教育中心": $dept_name = '职能管理部门';
					break;	
			}
			$authorcode = substr($authorcode,'1');

			$updatesql = "UPDATE db_patent_kh SET dept_name = '".$dept_name."',authorcode='".$authorcode."' where id = ".$v['id'];
			$updateP =$this->Patent_kh_model->execute($updatesql);
			// var_dump($v['id']);
			// var_dump($authorcode);
			// var_dump($dept_name);
		
		}
		echo "执行完毕";
		// var_dump($list);
        // redirect('/admin', 'refresh');
	}

}
